package com.atguigu.kafka.produce.demo;

import org.apache.kafka.clients.producer.ProducerInterceptor;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

import java.util.Map;

/**
 * @ClassName MyInterceptor
 * @DeScription MyInterceptor
 * @Author 剧情再美终是戏
 * @Date 2019/12/4 18:38
 * @Version 1.0
 **/
public class MyCountInterceptor implements ProducerInterceptor<Integer, String> {

    private int successNum;
    private int failNum;

    public ProducerRecord<Integer, String> onSend(ProducerRecord<Integer, String> record) {
        return record;
    }

    public void onAcknowledgement(RecordMetadata metadata, Exception exception) {
        if (null == exception) {
            successNum++;
        } else {
            failNum++;
        }
    }

    public void close() {
        System.out.printf("成功条数：%d, 失败条数：%d%n", successNum, failNum);
    }

    public void configure(Map<String, ?> configs) {

    }


}
